package com.hphs.controller;

import com.hphs.model.Category;
import com.hphs.model.CategoryQuery;
import com.hphs.model.Product;
import com.hphs.model.ProductQuery;
import com.hphs.service.CategoryService;
import com.hphs.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

// 告诉前端 我给你一个地址 就能获取数据 其他不要找我
// http://localhost:8080/api/category
@RestController
//@CrossOrigin   // 用来解决跨域访问的问题
@RequestMapping("/api/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    @GetMapping
    public List<Product> select(ProductQuery query){
        return productService.select(query);
    }

    @PostMapping
    public Integer insert(@RequestBody Product product){
        return productService.insert(product);
    }

    @PutMapping
    public Integer update(@RequestBody Product product){
        return productService.update(product);
    }

    @DeleteMapping
    public Integer delete(Integer id){
        return productService.updateStatus(id);
    }

}
